package com.zhaoc.ioc.container;

/** 
 * <br>类 名: XmlApplicationContext
 * <br>描 述: 提供默认的实现
 * <br>作 者: zhaoc
 * <br>创 建: 2015年8月18日
 * <br>版 本: v1.0.0
 * <br>
 * <br>历 史: (版本) 作者 时间 注释 
 */
public class XmlApplicationContext extends AbstractApplicationContext {
	
	private XmlApplicationContext() { }
	
	private static class SingleHolder {
		static final ApplicationContext container = new XmlApplicationContext();
	}
	
	public static ApplicationContext getContainer() {
		return SingleHolder.container;
	}
	/**
	 * <p> 此处实际就是父类默认的实现
	 */
	@Override
	protected <T> T getInstance(Class<T> interfaceType, String name, Context context) {
		InternalFactory factory = factorys.get(Key.newInstance(name, interfaceType));
		if(factory == null)
			throw new NullPointerException("internal factory is null, initialzation failed !");
		return factory.create(context);
	}
}
